package com.blyat.xsoft.kernel.component.security;


import com.blyat.xsoft.kernel.restful.view.ResultModel;
import com.blyat.xsoft.kernel.util.ServletUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther: syh
 * @Date: 2020/7/14
 * @Description:
 */
public class SecurityLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        //清空上下文
        SecurityContextHolder.clearContext();

        ServletUtil.writer(ResultModel.SUCCESS("退出成功"));
    }
}
